<?php
	require_once("../../oh.framework/oh.framework.php");
	oh("config")->file("config.php");
?>
<html>
<head>
	<?php echo oh("css")->link("style.css"); ?>
</head>
<body class="reset">
	<div class="inner-panel">
	<h2 class="title-panel">Option - info.francescobianco@gmail.com</h2>
	<?php
		if (oh("simpleform")->onsubmit("formnew")) {
			oh("frecord")->prepend( 
				oh("config.file"),
				oh("simpleform.formnew.newlabel").'|'.
				oh("url.tools")->sanitize(oh("simpleform.formnew.newurl"))
			);
		}
		oh("simpleform")->open("optionform");
			oh("simpleform")->text("newlabel");
			oh("simpleform")->text("newurl");
			oh("simpleform")->submit("newurl");
		oh("simpleform")->close();
		
		$tabs = oh("frecord")->get(oh("config.file"));
		foreach($tabs as $id=>$tab) {
			if (oh("simpleform")->onsubmit("formrow_".$id)) {
				$action = explode(":",oh("simpleform.formrow_{$id}.onsubmitdata"));
				if ($action[0] == "up") {
					if ($id>0) {
						oh("frecord")->move(oh("config.file"),$id,$id-1);
					}				
				}
				if ($action[0] == "dw") {
					oh("frecord")->move(oh("config.file"),$id,$id+1);				
				}
				if ($action[0] == "md") {
					oh("frecord")->modify(oh("config.file"),$id,
						oh("simpleform.formrow_".$id.".thelabel").'|'.
						oh("url.tools")->sanitize(oh("simpleform.formrow_{$id}.theurl"))
					);										
				}
				if ($action[0] == "dl") {
					oh("frecord")->delete(oh("config.file"),$id);								
				}				
			}
		}		

		$tabs = oh("frecord")->get(oh("config.file"));	
		foreach($tabs as $id=>$tab) {
			$tab = explode("|",$tab);

			oh("simpleform")->open("formrow_".$id);
			echo '<div class="row-panel">';
				oh("simpleform")->text("thelabel",$tab[0]);
				oh("simpleform")->text("theurl",$tab[1]);
				oh("simpleform")->submit("up","up:$id");
				oh("simpleform")->submit("dw","dw:$id");
				oh("simpleform")->submit("modify","md:$id");
				oh("simpleform")->submit("delete","dl:$id");
			echo '</div>';
			oh("simpleform")->close();
		}
	?>
	</div>
</body>
</html>
